package com.elink.enginerring.library;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.common.BaseCo;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;
import com.elink.enginerring.library.service.ILibCommentService;

@Controller
@RequestMapping("view/thesis/comment")
@Api(value="论文评论接口")
@ResponseBody
public class LibCommentController {
	@Autowired
	private ILibCommentService libCommentService;
	
	/**
	 * 分页获取列表
	 * @param bc
	 * @param type 0--未审核 1--已经审核 
	 * @return
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ApiOperation(value="获取论文评论列表",httpMethod="GET",notes="分页获取论文评论列表")
	public Map<String, Object> getList(
			@ModelAttribute @Valid BaseCo bc,
			@ApiParam(value="是否认证,1--认证通过2--未通过认证，默认为null",defaultValue="",required=false)
			@RequestParam(value="type",defaultValue="",required=true)String type) {
		DataSourceContextHolder.setDbType(DataSourceType.DBLIBRARY);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return libCommentService.getListOfPage(bc,type);
	}
	
	/**
	 * 审核评论
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="addAuth",method=RequestMethod.GET)
	@ApiOperation(value="审核评论",httpMethod="GET",notes="审核评论")
	public Map<String, Object>addAuth(@ApiParam(value="评论ids,比如'1,2,3'",required=true)
	@RequestParam(value="ids",required=true)String ids,
	@ApiParam(value="评论审核,1--通过审核，2--不通过审核,默认为0--审核中",required=true,defaultValue="0")
	@RequestParam(value="authStatus",required=true,defaultValue="0")int authStatus){
		
		DataSourceContextHolder.setDbType(DataSourceType.DBLIBRARY);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		
		return libCommentService.addAuth(ids,authStatus);
	}

}
